package com.attendance.java;

import java.util.ArrayList;
import java.util.List;

/**
 * 字符串跑龙套
 *
 * @author 今朝
 * @date 2021/03/17
 */
public class StringUtils {
    private static final String SPLIT_COMMA = ",";

    public static List<Long> strToIdsByComma(String str) {
        List<Long> ids = new ArrayList<>();
        for (String id : str.split(SPLIT_COMMA)) {
            if (! "".equals(id)) {
                ids.add(Long.valueOf(id));
            }
        }
        return ids;
    }

    public static String getFilePrefix(String fileName) {
        int splitIndex = fileName.lastIndexOf(".");
        return fileName.substring(0, splitIndex).replaceAll("\\s*", "");
    }

    public static String getExtend(String filename, String defExt) {
        if ((filename != null) && (filename.length() > 0)) {
            int i = filename.lastIndexOf('.');

            if ((i > 0) && (i < (filename.length() - 1))) {
                return (filename.substring(i + 1)).toLowerCase();
            }
        }
        return defExt.toLowerCase();
    }
}
